home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Environments / Oberon⁄F™ 1.2 / Preinstalled version / System / Docu / Stores (.txt) < prev    next >
Encoding:
Oberon Document  |  1996-07-08  |  20.3 KB  |  355 lines  |  [oODC/obnF]

  1. Documents.StdDocumentDesc
  2. Documents.DocumentDesc
  3. Containers.ViewDesc
  4. Views.ViewDesc
  5. Stores.StoreDesc
  6. Documents.ModelDesc
  7. Containers.ModelDesc
  8. Models.ModelDesc
  9. Stores.ElemDesc
  10. TextViews.StdViewDesc
  11. TextViews.ViewDesc
  12. TextModels.StdModelDesc
  13. TextModels.ModelDesc
  14. TextModels.AttributesDesc
  15. Helvetica
  16. TextRulers.StdRulerDesc
  17. TextRulers.RulerDesc
  18. TextRulers.StdStyleDesc
  19. TextRulers.StyleDesc
  20. TextRulers.AttributesDesc
  21. Helvetica
  22. Helvetica
  23. Helvetica
  24. Helvetica
  25. Stores
  26. DEFINITION Stores;
  27.     IMPORT Domains, Files;
  28.     CONST
  29.         alienVersion = 1; alienComponent = 2;
  30.         inconsistentVersion = -1; inconsistentType = -2; moduleFileNotFound = -3;
  31.         invalidModuleFile = -4; inconsModuleVersion = -5; typeNotFound = -6;
  32.     TYPE
  33.         LONGCHAR = INTEGER;
  34.         TypeName = ARRAY 64 OF CHAR;
  35.         TypePath = ARRAY 16 OF TypeName;
  36.         Store = POINTER TO StoreDesc;
  37.         StoreDesc = RECORD
  38.             PROCEDURE (s: Store) InitDomain (d: Domains.Domain);
  39.             PROCEDURE (s: Store) Internalize (VAR rd: Reader);
  40.             PROCEDURE (s: Store) Externalize (VAR wr: Writer)
  41.         END;
  42.         Elem = POINTER TO ElemDesc;
  43.         ElemDesc = RECORD (StoreDesc)
  44.             domain-: Domains.Domain
  45.         END;
  46.         Reader = RECORD
  47.             rider-: Files.Reader;
  48.             cancelled-: BOOLEAN;
  49.             readAlien-: BOOLEAN;
  50.             PROCEDURE (VAR rd: Reader) ConnectTo (f: Files.File);
  51.             PROCEDURE (VAR rd: Reader) Pos (): LONGINT;
  52.             PROCEDURE (VAR rd: Reader) SetPos (pos: LONGINT);
  53.             PROCEDURE (VAR rd: Reader) ReadBool (VAR x: BOOLEAN);
  54.             PROCEDURE (VAR rd: Reader) ReadChar (VAR x: CHAR);
  55.             PROCEDURE (VAR rd: Reader) ReadLChar (VAR x: LONGCHAR);
  56.             PROCEDURE (VAR rd: Reader) ReadSInt (VAR x: SHORTINT);
  57.             PROCEDURE (VAR rd: Reader) ReadInt (VAR x: INTEGER);
  58.             PROCEDURE (VAR rd: Reader) ReadLInt (VAR x: LONGINT);
  59.             PROCEDURE (VAR rd: Reader) ReadReal (VAR x: REAL);
  60.             PROCEDURE (VAR rd: Reader) ReadLReal (VAR x: LONGREAL);
  61.             PROCEDURE (VAR rd: Reader) ReadSet (VAR x: SET);
  62.             PROCEDURE (VAR rd: Reader) ReadString (VAR x: ARRAY OF CHAR);
  63.             PROCEDURE (VAR rd: Reader) ReadLString (VAR x: ARRAY OF LONGCHAR);
  64.             PROCEDURE (VAR rd: Reader) ReadStore (VAR x: Store);
  65.             PROCEDURE (VAR rd: Reader) ReadVersion (min, max: SHORTINT; VAR version: SHORTINT);
  66.             PROCEDURE (VAR rd: Reader) TurnIntoAlien (cause: LONGINT)
  67.         END;
  68.         Writer = RECORD
  69.             rider-: Files.Writer;
  70.             PROCEDURE (VAR wr: Writer) ConnectTo (f: Files.File);
  71.             PROCEDURE (VAR wr: Writer) Pos (): LONGINT;
  72.             PROCEDURE (VAR wr: Writer) SetPos (pos: LONGINT);
  73.             PROCEDURE (VAR wr: Writer) WriteBool (x: BOOLEAN);
  74.             PROCEDURE (VAR wr: Writer) WriteChar (x: CHAR);
  75.             PROCEDURE (VAR wr: Writer) WriteLChar (x: LONGCHAR);
  76.             PROCEDURE (VAR wr: Writer) WriteSInt (x: SHORTINT);
  77.             PROCEDURE (VAR wr: Writer) WriteInt (x: INTEGER);
  78.             PROCEDURE (VAR wr: Writer) WriteLInt (x: LONGINT);
  79.             PROCEDURE (VAR wr: Writer) WriteReal (x: REAL);
  80.             PROCEDURE (VAR wr: Writer) WriteLReal (x: LONGREAL);
  81.             PROCEDURE (VAR wr: Writer) WriteSet (x: SET);
  82.             PROCEDURE (VAR wr: Writer) WriteString (x: ARRAY OF CHAR);
  83.             PROCEDURE (VAR wr: Writer) WriteLString (x: ARRAY OF LONGCHAR);
  84.             PROCEDURE (VAR wr: Writer) WriteStore (x: Store);
  85.             PROCEDURE (VAR wr: Writer) WriteVersion (version: SHORTINT)
  86.         END;
  87.         AlienComp = POINTER TO AlienCompDesc;
  88.         AlienCompDesc = RECORD
  89.             next-: AlienComp
  90.         END;
  91.         Alien = POINTER TO AlienDesc;
  92.         AlienDesc = RECORD (StoreDesc)
  93.             path-: TypePath;
  94.             cause-: LONGINT;
  95.             file-: Files.File;
  96.             comps-: AlienComp
  97.         END;
  98.         AlienElem = POINTER TO AlienElemDesc;
  99.         AlienElemDesc = RECORD (ElemDesc)
  100.             path-: TypePath;
  101.             cause-: LONGINT;
  102.             file-: Files.File;
  103.             comps-: AlienComp
  104.         END;
  105.         AlienPart = POINTER TO AlienPartDesc;
  106.         AlienPartDesc = RECORD (AlienCompDesc)
  107.             store-: Store
  108.         END;
  109.         AlienPiece = POINTER TO AlienPieceDesc;
  110.         AlienPieceDesc = RECORD (AlienCompDesc)
  111.             pos-, len-: LONGINT
  112.         END;
  113.     VAR ReportMsg: PROCEDURE (msg, p0, p1, p2: ARRAY OF CHAR);
  114.     PROCEDURE Clone (s: Store): Store;
  115.     PROCEDURE New (type: TypeName): Store;
  116.     PROCEDURE GetTypeName (s: Store; VAR type: TypeName);
  117.     PROCEDURE Report (msg, p0, p1, p2: ARRAY OF CHAR);
  118.     PROCEDURE SameType (s0, s1: Store): BOOLEAN;
  119. END Stores.
  120. Module Stores defines a data type Store, which should be used as base type of all storable extensible objects. When storing an object of an extensible type, it is necessary to store not only its contents but also its particular type. The type is needed to create an object of the correct type when reading the data in again.
  121. A variable of (an extension of) type Store is stored in a file. A store must implement the Internalize procedure which takes a Reader as parameter, and the Externalize procedure which takes a Writer as parameter. Readers and writers are mappers on files. The types Views.View and TextModels.Model are examples of Store extensions.
  122. The contents of a store is stored in a file. When reading the same file by another Oberon configuration, it may occur that not all necessary modules are available in this configuration, i.e. the module which defines the store's type cannot be loaded. Yet reading such an "alien" store does not fail completely. Instead of the correct store type, an "alien" object is generated. Obviously such an alien cannot interpret the data it represents, and therefore cannot provide any special behavior. However, it may be copied and stored into another file, such that its contents on the new file are intact and consistent.
  123. Elements are special stores which belong to a particular domain (-> Domains). The elements of a domain can be externalized and internalized such that pointers among them are reconstructed correctly upon internalization. In particular, alias pointers are handled correctly: if several elements point to another element of the same domain, this element is read in only once, and all the pointers to it are rebuilt. Arbitrary graphs can be handled this way, e.g. cyclic data structures. Links to elements of other domains are prohibited. Pointers to non-element stores yield the same store again upon internalization, but alias pointers are not handled: if several elements (or stores) point to a store, internalization creates one new store per pointer, such that each element gets its own independent instance of the store.
  124. Stores provides a pair of mapper types, which are used as parameters in a store's Internalize and Externalize procedures. These readers/writers use the following external (little endian) format:
  125. BOOLEAN
  126.     1 byte (0 = FALSE, 1 = TRUE)
  127.     1 byte in the Latin-1 character set (i.e. Unicode page 0; 00X..0FFX)
  128. LONGCHAR
  129.     2 byte in the Unicode character set (0000H..0FFFFH)
  130. SHORTINT
  131.     1 byte (-128..127)
  132. INTEGER
  133.     2 bytes (-32768..32767)
  134. LONGINT
  135.     4 bytes (-2147483648..2147483647)
  136.     4 bytes IEEE format
  137. LONGREAL
  138.     8 bytes IEEE format
  139.     4 bytes (least significant bit = element 0)
  140. String
  141.     string in the Latin-1 character set, followed by a 00X
  142. Long String
  143.     string in the Unicode character set, followed by a 0000H
  144. CONST alienVersion
  145. This value is assigned to a Reader's cause field if Reader.ReadVersion read a version outside of the specified range.
  146. CONST alienComponent
  147. This value can be used as cause parameter to Reader.TurnIntoAlien to indicate that the store itself could be read, but that some store contained in it is an alien. As an example, a view may turn itself into an alien if its model is an alien.
  148. CONST inconsistentVersion
  149. This value is assigned to a Reader's cause field if Reader.ReadVersion read a data block which has an inconsistent length, i.e. not all of its data have been read, or it has been attempted to read beyond the end of the data.
  150. CONST inconsistentType
  151. This value is assigned to a Reader's cause field if Reader.ReadVersion detected a change in the type extension hierarchy of the internalized type.
  152. CONST moduleFileNotFound
  153. This value is assigned to a Reader's cause field if Reader.ReadVersion tried to load a module defining an internalized type, and the codefile for this module couldn't be found.
  154. CONST invalidModuleFile
  155. This value is assigned to a Reader's cause field if Reader.ReadVersion tried to load a module defining an internalized type, and the module couldn't be loaded because it imports another module which cannot be loaded for some reason.
  156. CONST inconsModuleVersion
  157. This value is assigned to a Reader's cause field if Reader.ReadVersion tried to load a module defining an internalized type, and the module couldn't be loaded because its version is inconsistent with some already loaded module.
  158. CONST typeNotFound
  159. This value is assigned to a Reader's cause field if Reader.ReadVersion tried to internalize a non-existing type (the module was found, however).
  160. TYPE LONGCHAR
  161. Type for 2-byte characters in the Unicode character set.
  162. TYPE TypeName
  163. String type for the type name of an object.
  164. TYPE TypePath
  165. Array of type names.
  166. TYPE Store
  167. Interface
  168. Storable extensible data types like Views.View or TextModels.Text are derived from Store.
  169. Stores are allocated by suitable directories, e.g. Views.Directory or TextModels.Directory.
  170. Stores are used as base types for all extensible and persistent objects.
  171. PROCEDURE (s: Store) InitDomain (d: Domains.Domain)
  172. A store may be associated with a domain. Such an association may not be changed anymore.
  173. InitDomain is extended by stores which may contain other stores, to propagate the domain to them.
  174. Super call is mandatory in an InitDomain extension.
  175. Not all stores support domains; for such stores InitDomain can be considered empty, except for the first two of the following precondition checks:
  176. domain(s) = NIL  OR  domain(s) = d    22
  177. s supports domain
  178.     dom(s) = d
  179. PROCEDURE (s: Store) Internalize (VAR rd: Reader)
  180. Reads the contents of s from reader rd. Internalize must read the same (amount of) data as is written by the corresponding Externalize procedure.
  181. Internalize is called internally.
  182. Internalize is extended by various persistent object types, e.g. models, views, and controllers.
  183. Extensions must make a super call first.
  184. PROCEDURE (s: Store) Externalize (VAR wr: Writer)
  185. Write the contents of s to writer wr. Externalize must write the same (amount of) data as is read by the corresponding Internalize procedure.
  186. Externalize ist called internally.
  187. Externalize is extended by various persistent object types, e.g. models, views, and controllers.
  188. Extensions must make a super call first.
  189. TYPE Elem
  190. Interface, Extension
  191. Store readers and writers handle pointers between Elem objects of the same domain such that aliases are handled correctly. This means that elements of a domain can form an arbitrary graph, which can be written and read in again without losing its structure. Element pointers must be written/read using Writer.WriteStore and Reader.ReadStore.
  192. domain-: Domains.Domain
  193. The element's domain, which is initialized by the InitDomain procedure.
  194. TYPE Reader
  195. Reader for Oberon/L values like integers, reals, or sets. A reader contains a Files.File, to which it forwards most operations.
  196. Readers are used in the Store.Internalize procedure.
  197. Readers are not extended.
  198. rider-: Files.Reader
  199. The file rider which links a Reader to a file.
  200. cancelled-: BOOLEAN    valid during a Store.Internalize call
  201. Tells whether the currently executing Internalize has been called by ReadVersion or TurnIntoAlien.
  202. readAlien-: BOOLEAN
  203. Tells whether any alien has been read since the last ConnectTo.
  204. PROCEDURE (VAR rd: Reader) ConnectTo (f: Files.File)
  205. Connect the reader to a file. All the following operations require connected readers, i.e. rd.rider # NIL. This precondition is not checked explicitly, however. After connecting, the reader's position is at the beginning of the file. If the same reader should be reused on another file, it must first be closed, by connecting it to NIL.
  206. ConnectTo is used internally.
  207. f = NIL
  208.     rd.rider = NIL
  209. f # NIL
  210.     (rd.rider # NIL) & (rd.rider.Base() = f)
  211.     rd.Pos() = 0
  212. PROCEDURE (VAR rd: Reader) Pos (): LONGINT
  213. Returns the reader's current position.
  214. 0 <= result <= rd.rider.Base().Length()
  215. PROCEDURE (VAR rd: Reader) SetPos (pos: LONGINT)
  216. Sets the reader's current position to pos.
  217. pos >= 0    20
  218. pos <= rd.rider.Base().Length()    21
  219. rd.Pos() = pos
  220. ~rd.rider.eof
  221. PROCEDURE (VAR rd: Reader) ReadBool (VAR x: BOOLEAN)
  222. Reads a Boolean value.
  223. PROCEDURE (VAR rd: Reader) ReadChar (VAR x: CHAR)
  224. Reads a character (00X..0FFX).
  225. PROCEDURE (VAR rd: Reader) ReadLChar (VAR x: LONGCHAR)
  226. Reads a long character (0000H..0FFFFH).
  227. PROCEDURE (VAR rd: Reader) ReadSInt (VAR x: SHORTINT)
  228. Reads a short integer (-128..127).
  229. PROCEDURE (VAR rd: Reader) ReadInt (VAR x: INTEGER)
  230. Reads an integer (-32768..32767).
  231. PROCEDURE (VAR rd: Reader) ReadLInt (VAR x: LONGINT)
  232. Reads a long integer (-2147483648..2147483647).
  233. PROCEDURE (VAR rd: Reader) ReadReal (VAR x: REAL)
  234. Reads a real (32-bit IEEE number).
  235. PROCEDURE (VAR rd: Reader) ReadLReal (VAR x: LONGREAL)
  236. Reads a long real (64-bit IEEE number).
  237. PROCEDURE (VAR rd: Reader) ReadSet (VAR x: SET)
  238. Reads a set (32 elements).
  239. PROCEDURE (VAR rd: Reader) ReadString (VAR x: ARRAY OF CHAR)
  240. Reads a 00X-terminated string.
  241. LEN(x) > Length(string)    invalid index 
  242. PROCEDURE (VAR rd: Reader) ReadLString (VAR x: ARRAY OF LONGCHAR)
  243. Reads a 0000H-terminated string.
  244. LEN(x) > Length(string)    invalid index 
  245. PROCEDURE (VAR rd: Reader) ReadStore (VAR x: Store)
  246. Reads a store's type, allocates it, and then reads its contents, by calling the store's Internalize procedure. x may also be NIL, or an alien if the store's module cannot be loaded, or if internalization has been cancelled by the Internalize procedure.
  247. If the store is an Elem which has already been read in, a pointer to the same Elem is returned instead of allocating a new one.
  248. empty store on file
  249.     x = NIL
  250. non-empty store on file
  251.     x # NIL
  252.         x IS Alien
  253.             x.cause # 0
  254.             x.type # ""
  255.             x.file # NIL
  256.             x.pos >= 0    beginning of store's data
  257.             x.len >= 0    length of store's data
  258.             alien store contents are on x.file in the range [x.pos .. x.pos + x.len[.
  259.             These data include only the store's contents, not its prefix
  260.         ~(x IS Alien)
  261.             x was read successfully
  262. PROCEDURE (VAR rd: Reader) ReadVersion (min, max: SHORTINT; VAR version: SHORTINT)
  263. Read a version byte and return it in version. If version is not in the specified range [min .. max], the store currently being read is turned into an alien, with cause = alienVersion.
  264. 0 <= min <= max    20
  265. min <= version <= max
  266.     legal version
  267. (version < min) OR (version > max)
  268.     illegal version
  269.     rd.cause = alienVersion
  270.     rd.cancelled
  271.     rd.readAlien
  272. PROCEDURE (VAR rd: Reader) TurnIntoAlien (cause: LONGINT)
  273. A store which is currently being internalized can turn itself into an alien, e.g. if it has read a component store which is an alien.
  274. cause > 0    20
  275. TYPE Writer
  276. Writer for Oberon/L values like integers, reals, or sets. A writer contains a Files.Writer, to which it forwards most operations.
  277. Writers are used in the Stores.Externalize procedure.
  278. Writers are not extended.
  279. rider-: Files.Writer
  280. A file rider which links a Writer to a file.
  281. PROCEDURE (VAR wr: Writer) ConnectTo (f: Files.File)
  282. Connect the writer to a file. All the following operations require connected writers, i.e. wr.rider # NIL. This precondition is not checked explicitly, however. After connecting, the writer's position is at the end of the file. If the same writer should be reused on another file, it must first be closed, by connecting it to NIL.
  283. ConnectTo is used internally.
  284. f = NIL
  285.     wr.rider = NIL
  286. f # NIL
  287.     wr.rider # NIL  &  wr.rider.Base() = f
  288.     wr.Pos() = wr.rider.Base().Length()
  289. PROCEDURE (VAR wr: Writer) Pos (): LONGINT
  290. Returns the writer's current position.
  291. 0 <= result <= wr.rider.Base().Length()
  292. PROCEDURE (VAR wr: Writer) SetPos (pos: LONGINT)
  293. Sets the writer's current position to pos.
  294. pos >= 0    20
  295. pos <= wr.rider.Base().Length()    21
  296. wr.Pos() = pos
  297. PROCEDURE (VAR wr: Writer) WriteBool (x: BOOLEAN)
  298. Writes a Boolean value.
  299. PROCEDURE (VAR wr: Writer) WriteChar (x: CHAR)
  300. Writes a character (00X..0FFX).
  301. PROCEDURE (VAR wr: Writer) WriteLChar (x: LONGCHAR)
  302. Writes a character (0000H..0FFFFH).
  303. PROCEDURE (VAR wr: Writer) WriteSInt (x: SHORTINT)
  304. Writes a short integer (-128..127).
  305. PROCEDURE (VAR wr: Writer) WriteInt (x: INTEGER)
  306. Writes an integer (-32768..32767).
  307. PROCEDURE (VAR wr: Writer) WriteLInt (x: LONGINT)
  308. Writes a long integer (-2147483648..2147483647).
  309. PROCEDURE (VAR wr: Writer) WriteReal (x: REAL)
  310. Writes a real (32-bit IEEE number).
  311. PROCEDURE (VAR wr: Writer) WriteLReal (x: LONGREAL)
  312. Writes a long real (64-bit IEEE number).
  313. PROCEDURE (VAR wr: Writer) WriteSet (x: SET)
  314. Writes a set (32 elements).
  315. PROCEDURE (VAR wr: Writer) WriteString (x: ARRAY OF CHAR)
  316. Writes a 00X-terminated string.
  317. PROCEDURE (VAR wr: Writer) WriteLString (x: ARRAY OF LONGCHAR)
  318. Writes a 0000H-terminated string.
  319. PROCEDURE (VAR wr: Writer) WriteStore (x: Store)
  320. Writes the store's type and then its contents, by calling the store's Externalize procedure. x may also be NIL, or an alien.
  321. wr.rider # NIL    20
  322. all Elem stores must be of the same domain during an externalization    21
  323. PROCEDURE WriteVersion (version: SHORTINT)
  324. Writes a version byte.
  325. version >= 0    20
  326. TYPE Alien, AlienComp, AlienElem, AlienPart, AlienPiece
  327. These auxiliary types are used internally, to handle alien stores.
  328. VAR ReportMsg: PROCEDURE (msg, p0, p1, p2: ARRAY OF CHAR)
  329. Used internally.
  330. PROCEDURE New (type: TypeName): Store
  331. Given the name of a store type in the form "module.record", New returns an object of this type. If the defining module is not yet loaded, New tries to load it. If it cannot be loaded, if there is not enough memory, or if the module doesn't define this type, New returns NIL.
  332. New is called internally.
  333. result = NIL
  334.     type not available
  335. result # NIL
  336.     type available
  337.     result has desired type
  338. PROCEDURE Clone (s: Store): Store
  339. Returns the clone of a store. 
  340. Clone allocates a new and uninitialized record with the same dynamic type as s.
  341. s # NIL    20
  342. PROCEDURE GetTypeName (s: Store; VAR type: TypeName)
  343. Returns the name of a store's record type.
  344. PROCEDURE Report (msg, p0, p1, p2: ARRAY OF CHAR)
  345. Used internally.
  346. PROCEDURE SameType (s0, s1: Store): BOOLEAN
  347. Tests whether s0 and s1 both have exactly the same dynamic type.
  348. s0 # NIL  &  s1 # NIL    20
  349. TextControllers.StdCtrlDesc
  350. TextControllers.ControllerDesc
  351. Containers.ControllerDesc
  352. Controllers.ControllerDesc
  353. Helvetica
  354. Documents.ControllerDesc
  355.